package cn.iocoder.yudao.module.picturebook.controller.admin.picturepost;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.picturebook.controller.admin.picturepost.vo.*;
import cn.iocoder.yudao.module.picturebook.dal.dataobject.picturepost.PicturePostDO;
import cn.iocoder.yudao.module.picturebook.service.picturepost.PicturePostService;

@Tag(name = "绘本系统 - 帖子")
@RestController
@RequestMapping("/picturebook/post")
@Validated
public class PicturePostController {

    @Resource
    private PicturePostService PicturePostService;

    @PostMapping("/create")
    @Operation(summary = "创建帖子")
    @PreAuthorize("@ss.hasPermission('picturebook:post:create')")
    public CommonResult<Long> createPost(@Valid @RequestBody PicturePostSaveReqVO createReqVO,@RequestHeader("token") Long userId) {
        return success(PicturePostService.createPost(createReqVO, userId));
    }

    /*@PutMapping("/update")
    @Operation(summary = "更新帖子")
    @PreAuthorize("@ss.hasPermission('picturebook:post:update')")
    public CommonResult<Boolean> updatePost(@Valid @RequestBody PicturePostSaveReqVO updateReqVO) {
        PicturePostService.updatePost(updateReqVO);
        return success(true);
    }*/

    /*@DeleteMapping("/delete")
    @Operation(summary = "删除帖子")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('picturebook:post:delete')")
    public CommonResult<Boolean> deletePost(@RequestParam("id") Long id) {
        PicturePostService.deletePost(id);
        return success(true);
    }*/

    /*@DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除帖子")
                @PreAuthorize("@ss.hasPermission('picturebook:post:delete')")
    public CommonResult<Boolean> deletePostList(@RequestParam("ids") List<Long> ids) {
        PicturePostService.deletePostListByIds(ids);
        return success(true);
    }*/

    /*@GetMapping("/get")
    @Operation(summary = "获得帖子")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('picturebook:post:query')")
    public CommonResult<PicturePostRespVO> getPost(@RequestParam("id") Long id) {
        PicturePostDO post = PicturePostService.getPost(id);
        return success(BeanUtils.toBean(post, PicturePostRespVO.class));
    }*/

    @GetMapping("/page")
    @Operation(summary = "获得帖子分页")
    @PreAuthorize("@ss.hasPermission('picturebook:post:query')")
    public CommonResult<PageResult<PicturePostRespVO>> getPostPage(@Valid PicturePostPageReqVO pageReqVO,@RequestHeader("token") Long userId) {
        PageResult<PicturePostRespVO> pageResult = PicturePostService.getPostPage(pageReqVO, userId);
        return success(pageResult);
    }

   /* @GetMapping("/export-excel")
    @Operation(summary = "导出帖子 Excel")
    @PreAuthorize("@ss.hasPermission('picturebook:post:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportPostExcel(@Valid PicturePostPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<PicturePostRespVO> list = PicturePostService.getPostPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "帖子.xls", "数据", PicturePostRespVO.class,
                        BeanUtils.toBean(list, PicturePostRespVO.class));
    }*/

}